<!-- 
 - Copyright 2012 OmniFaces.
 -
 - Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 - the License. You may obtain a copy of the License at
 -
 -     http://www.apache.org/licenses/LICENSE-2.0
 -
 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 - an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 - specific language governing permissions and limitations under the License.
 -->
<ui:composition template="/WEB-INF/templates/layout.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:o="http://omnifaces.org/ui"
	xmlns:of="http://omnifaces.org/functions"
	xmlns:os="http://omnifaces.org/showcase"
>
	<ui:define name="title">#{page.current.title} - OmniFaces Showcase</ui:define>

	<ui:define name="contentTitle">
		<!-- 
			The below p:selectOneMenu components are disabled in other phases than render response, because they 
			otherwise complain that the model value cannot be set even though there's no form. 
			See also http://stackoverflow.com/q/14068891/157882
		 -->
		<c:set var="parent" value="#{page.current.parent}" />
		<p:selectOneMenu id="groups" value="#{parent.children[0].viewId}" onchange="window.location='#{request.contextPath}' + this.value" 
			styleClass="groups" panelStyleClass="groups" height="#{26 * (fn:length(parent.parent.children) - 1)}" effect="fade" 
			disabled="#{facesContext.postback and not facesContext.renderResponse}">
			<f:selectItems value="#{parent.parent.children}" var="_parent" itemValue="#{_parent.children[0].viewId}" itemLabel="#{_parent.title}" 
				itemDisabled="#{_parent.children[0] == parent.children[0]}" />
		</p:selectOneMenu>
		-
		<p:selectOneMenu id="pages" value="#{page.current.viewId}" onchange="window.location='#{request.contextPath}' + this.value" 
			styleClass="pages" panelStyleClass="pages" height="#{(19 * (fn:length(parent.children) - 1)) + 10}" effect="fade" 
			disabled="#{facesContext.postback and not facesContext.renderResponse}" rendered="#{parent.childCount gt 1}">
			<f:selectItems value="#{parent.children}" var="_page" itemValue="#{_page.viewId}" itemLabel="#{_page.title}" 
				itemDisabled="#{_page == page.current}" />
		</p:selectOneMenu>
		<h:outputText value="#{page.current.title}" styleClass="code" rendered="#{parent.childCount == 1}" />

		<div id="quickNavigation">
		 	<p:button icon="ui-icon-triangle-1-w" title="Previous" outcome="#{of:coalesce(page.current.previousSibling.viewId, '/index')}" />
		 	<p:button icon="ui-icon-triangle-1-e" title="Next" outcome="#{of:coalesce(page.current.nextSibling.viewId, '/index')}" />
		</div>
	</ui:define>

	<ui:define name="content">
		<h:outputStylesheet library="showcase" name="css/showcase.css" />
		<h:outputStylesheet library="showcase" name="css/prettify.css" />
		<h:outputScript library="showcase" name="js/prettify.js" target="head" />
		<h:outputScript library="showcase" name="js/onload.js" target="body" />

		<p:panel id="description" header="Description">
			<ui:insert name="description" />
		</p:panel>

		<ui:fragment rendered="#{not empty page.current.sources}">
			<p:panel id="demo" header="Demo">
				<ui:insert name="demo" />
				<o:highlight />
			</p:panel>

			<p:panel id="source" header="Source code">
				<p:tabView value="#{page.current.sources}" var="source">
					<p:tab title="#{source.title}">
						<pre class="prettyprint"><code class="lang-#{source.type}">#{source.code}</code></pre>
					</p:tab>
				</p:tabView>
			</p:panel>
		</ui:fragment>

		<p:panel id="documentation" header="Documentation" rendered="#{not empty page.current.documentation}">
			<os:listdocs header="VDL" docs="vdldocs" url="#{_vdlURL}#{path}.html" label="#{path.replace('/', ':')}" />
			<os:listdocs header="API" docs="apidocs" url="#{_apiURL}org/omnifaces/#{path}.html" label="org.omnifaces.#{path.replace('/', '.')}" />
			<os:listdocs header="Source code" docs="codes" url="#{_srcURL}org/omnifaces/#{path}.java#{_srcVersionParam}" label="org.omnifaces.#{path.replace('/', '.')}" />
		</p:panel>
	</ui:define>
</ui:composition>